//
//  MCSendRecordListAndTotalModel.m
//  XDYL
//
//  Created by MC on 2018/3/28.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCSendRecordListAndTotalModel.h"
#import "NSDictionary+helper.h"
#import "NSString+Helper.h"

@interface MCSendRecordListAndTotalModel ()<ApiManagerCallBackProtocol,ApiManagerProvider,ApiManagerProtocol>
{
    
    NSDictionary * _dic;
}
@end

@implementation MCSendRecordListAndTotalModel

- (instancetype)initWithDic:(NSDictionary *)dic{
    
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}



- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
};
-(BOOL)isShowHud{
    return YES;
}
- (BOOL)isShowError{
    return NO;
}
- (BOOL)isShowNoNet{
    return NO;
}
- (BOOL)isShowNodata{
    return NO;
}
- (enum ManagerRequestMethod)requestMethod{
    
    return ManagerRequestMethodRequestMethodRestPOST;
}

- (enum APIResponseDataType)responseDataType{
    
    return APIResponseDataTypeJson;
}
- (void)refreashDataAndShow{
    
    ApiBaseManager *baseManager = [[ApiBaseManager alloc] initWithUrlProvider:self];
    baseManager.apiCallBackDelegate = self;
    baseManager.requestCustomizeDelegate = self;
    [baseManager loadData];
    
}

- (NSDictionary<NSString *,NSString *> *)headerForManagerWithManager:(ApiBaseManager *)manager{
    
    NSString *Token=@"";
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"token"]) {
        Token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    }
    
    return @{@"token":Token,@"platformCode":@"5"};
}

- (NSString *)urlPathComponentForManagerWithManager:(ApiBaseManager *)manager{
    
    return @"web-api/api/v4/redenvelopes/getsendrecordlist";
//    /api/v1/redenvelopes/getsendrecordlist
//    获取发红包的记录、总金额、红包总个数

    
}

- (NSDictionary<NSString *,id> *)parametersForManagerWithManager:(ApiBaseManager *)manager{
    
    NSString *timeString = [NSString getCurrentTimestamp];
    
    NSDictionary *dic =_dic;
    NSString *jsonStr = [dic convertToJsonData];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",jsonStr,[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],timeString];
    return @{@"params":jsonStr,
             @"sign":[sign MD5],
             @"timestamp":timeString
             };
}

- (void)managerCallAPIDidSuccessWithManager:(ApiBaseManager *)manager{
    
    [BKIndicationView dismiss];
    if (self.callBackSuccessBlock) {
        self.callBackSuccessBlock(manager.ResponseRawData);
    }
    
}

- (void)managerCallAPIDidFailedWithManager:(ApiBaseManager *)manager errorCode:(NSString *)errorCode{
    [BKIndicationView dismiss];
    if (self.callBackFailedBlock) {
        self.callBackFailedBlock(manager,errorCode);
    }
    NSLog(@"er=----%@",errorCode);
}



@end



@implementation MCSendRecordTotalModel
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
};
@end


@implementation MCSendRecords
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
};
+(NSDictionary *)objectClassInArray
{
    return @{
             @"Records" : [MCRecordsModel class],
             };
}
@end


@implementation MCSendRecordsModel
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
};

+(MCSendRecordsModel *)getModelWithDic:(NSDictionary *)dic{
    MCSendRecordsModel * model = [[MCSendRecordsModel alloc]init];
    MCSendRecords * SendRecords = [MCSendRecords mj_objectWithKeyValues:dic[@"SendRecords"]];
    
    MCSendRecordTotalModel * SendRecordTotal = [MCSendRecordTotalModel mj_objectWithKeyValues:dic[@"SendRecordTotal"]];
    
    model.SendRecords=SendRecords;
    model.SendRecordTotal=SendRecordTotal;
    
    return model;
}

@end




//{
//    "SendRecords": {
//        "Paging": {
//            "PageIndex": 0,
//            "Total": 0,
//            "PageSize": 0,
//            "HasNextPage": true
//        },
//        "Records": [
//                    {
//                        "SysId": "string",
//                        "Mode": 0,
//                        "Amount": 0,
//                        "SendTime": "2018-03-28T06:12:16.480Z",
//                        "Qty": 0,
//                        "OpendedQty": 0,
//                        "Unopended": 0,
//                        "IsExpired": true
//                    }
//                    ]
//    },
//    "SendRecordTotal": {
//        "TotalAmount": 0,
//        "TotalQty": 0
//    }
//}



















